﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Projektarbete
{
    enum TileTypes { Impassable, Passable, DoorClosed, DoorOpen, Merchant, Chest };
     
    static class Collision
    {
        //För att kolla om man kan interacta med ett visst textureID
        public static Dictionary<ushort, bool> interactionDictionary;

        /// <summary>
        /// Tests collision of a tile given the textureID
        /// </summary>
        /// <param name="textureID">textureID to check</param>
        /// <returns>häst</returns>
        public static bool TestCollision(ushort textureID)
        {
            switch ((int)Math.Floor((double)textureID / 10))
            {
                case 0:
                    return false;
                case 1:
                    return true;
                case 2:
                    switch ((int)textureID % 10)
                    {
                        case 0:
                            return false;
                        case 1:
                            return true;
                        case 2:
                            return true;
                        default:
                            return true;
                    }
                default:
                    return true;
            }
        }

        /// <summary>
        /// Checks which type of tile this is (passable, impassable, merchant)
        /// </summary>
        /// <param name="textureID">Texture of the tile to get</param>
        /// <returns>häst</returns>
        public static TileTypes TileType(ushort textureID)
        {
            switch ((int)Math.Floor((double)textureID / 10))
            {
                case 0:
                    return TileTypes.Passable;
                case 1:
                    return TileTypes.Impassable;
                case 2:
                    switch ((int)textureID % 10)
                    {
                        case 0:
                            return TileTypes.DoorOpen;
                        case 1:
                            return TileTypes.DoorClosed;
                        case 2:
                            return TileTypes.Chest;
                    }
                    break;
            }

            throw new Exception("YOU DID WRONG. Hämta david");
        }

        /// <summary>
        /// Checks if a tile can be interacted with
        /// </summary>
        /// <param name="textureID">Texture of the tile to be interacted with</param>
        /// <returns>häst</returns>
        public static bool CanInteractWith(ushort textureID)
        {
            bool canInteract;

            interactionDictionary.TryGetValue(textureID, out canInteract);

            return canInteract;
        }

        /// <summary>
        /// Checks if a tile can be interacted with
        /// </summary>
        /// <param name="TileType">TileType of the tile to be interacted with</param>
        /// <returns>häst</returns>
        public static bool CanInteractWith(TileTypes TileType)
        {            
            switch (TileType)
            {
                case TileTypes.Impassable:
                    return false;
                case TileTypes.Passable:
                    return false;
                case TileTypes.DoorClosed:
                    return true;
                case TileTypes.DoorOpen:
                    return true;
                case TileTypes.Merchant:
                    return true;
                case TileTypes.Chest:
                    return true;
                default:
                    return false;
            }
        }
    }
}